/**
 * @param {number[]} nums1
 * @param {number[]} nums2
 * @return {number}
 */
var findMedianSortedArrays = function (nums1, nums2) {
  let arr = [...nums1, ...nums2].sort((a, b) => a - b);
  let length = arr.length;
  let length1 = Math.floor(arr.length / 2);

  if (length === 0) {
    return 0;
  }

  if (length % 2 === 1) {
    return arr[length1];
  }

  return (arr[length1 - 1] + arr[length1]) / 2;
};

let nums1 = [1, 1];
let nums2 = [1, 2];
console.time();
console.log(findMedianSortedArrays(nums1, nums2));
console.timeEnd();
